home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dircache.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  2KB  |  54 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Read and cache directory listings.
  5.  
  6. The listdir() routine returns a sorted list of the files in a directory,
  7. using a cache to avoid reading the directory more often than necessary.
  8. The annotate() routine appends slashes to directories.'''
  9. from warnings import warnpy3k
  10. warnpy3k('the dircache module has been removed in Python 3.0', stacklevel = 2)
  11. del warnpy3k
  12. import os
  13. __all__ = [
  14.     'listdir',
  15.     'opendir',
  16.     'annotate',
  17.     'reset']
  18. cache = { }
  19.  
  20. def reset():
  21.     '''Reset the cache completely.'''
  22.     global cache
  23.     cache = { }
  24.  
  25.  
  26. def listdir(path):
  27.     '''List directory contents, using cache.'''
  28.     
  29.     try:
  30.         (cached_mtime, list) = cache[path]
  31.         del cache[path]
  32.     except KeyError:
  33.         cached_mtime = -1
  34.         list = []
  35.  
  36.     mtime = os.stat(path).st_mtime
  37.     if mtime != cached_mtime:
  38.         list = os.listdir(path)
  39.         list.sort()
  40.     
  41.     cache[path] = (mtime, list)
  42.     return list
  43.  
  44. opendir = listdir
  45.  
  46. def annotate(head, list):
  47.     """Add '/' suffixes to directories."""
  48.     for i in range(len(list)):
  49.         if os.path.isdir(os.path.join(head, list[i])):
  50.             list[i] = list[i] + '/'
  51.             continue
  52.     
  53.  
  54.